home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Online / AmigaTalk / examples / ControlAGenerator.st < prev    next >
Text File  |  2002-01-30  |  2KB  |  54 lines

  1. " control the values produced by a generator "
  2.  
  3. Class ControlGenerator :Generator
  4. ! firstGenerator secondGenerator currentFirst 
  5.   currentSecond  controlBlock    computeBlock 
  6. !
  7. [
  8.    initA: fGen b: sGen control: aBlock compute: anotherBlock
  9.       firstGenerator <- fGen.
  10.       secondGenerator <- sGen.
  11.       controlBlock <- aBlock.
  12.       computeBlock <- anotherBlock
  13.  
  14. |   first
  15.       currentFirst <- firstGenerator first.
  16.       currentSecond <- secondGenerator first.
  17.       (currentFirst isNil & currentSecond isNil) ifTrue: [^ nil].
  18.       ^ self controlGeneratorNext
  19.  
  20. |   next
  21.       ^ self controlGeneratorNext
  22.  
  23. |   controlGeneratorNext   | control returnedValue |
  24.       control <- 0.
  25.       [ control anyMask: 12] 
  26.       
  27.         whileFalse: [
  28.  
  29.          control <- controlBlock value: currentFirst
  30.                   value: currentSecond.
  31.          (control allMask: 64) ifTrue: [^nil].
  32.          (control allMask: 32) ifTrue:
  33.             [currentFirst <- firstGenerator first].
  34.          (control allMask: 16) ifTrue:
  35.             [currentSecond <- secondGenerator first].
  36.          (control allMask: 12)
  37.          ifTrue:
  38.             [returnedValue <- computeBlock
  39.             value: currentFirst value: currentSecond]
  40.          ifFalse: [
  41.           (control allMask: 8) ifTrue:
  42.             [returnedValue <- computeBlock value: currentFirst].
  43.           (control allMask: 4) ifTrue:
  44.             [returnedValue <- computeBlock value: currentSecond].
  45.           ].
  46.          (control allMask: 2) ifTrue:
  47.             [currentFirst <- firstGenerator next].
  48.          (control allMask: 1) ifTrue:
  49.             [currentSecond <- secondGenerator next].
  50.          ].
  51.  
  52.       ^ returnedValue
  53. ]
  54.